package Operation;
import book.Booklist;
import book.*;

import java.util.Scanner;

public class DelOperation implements IOperation{
    public void work(Booklist booklist) {
        System.out.println("删除图书");
        int currentsize = booklist.getUsedSize();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入书名");
        String name = sc.nextLine();
        int flag = 0;
        for (int i = 0; i < currentsize; i++) {
            Book book = booklist.getBooks(i) ;
            if(book.getName().equals(name)){
                flag = i;
                break;
            }
        }
        if(flag==0){
            System.out.println("没有你要的书");
            return;
        }
        for (int i = flag; i <currentsize-1 ; i++) {
            Book book = booklist.getBooks(i+1);
            booklist.setBooks(i,book);
        }
        booklist.setUsedSize(currentsize-1);
    }
}
